package cn.cnsuh.剑指offer.q58_翻转单词顺序;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        // String[] arr = s.split(" ");
        // for (int i = 0; i < arr.length; i++) {
        //     System.out.print(arr[i]);
        // }
        System.out.println("reverseWords(s) = " + reverseWords(s));
    }

    static String reverseWords(String s) {
        String[] arr = s.split(" ");
        StringBuilder sb  = new StringBuilder();
        for (int i = arr.length; i >= 0; i++) {
            sb.append(" ");
            sb.append(arr[i].trim());
        }
        return sb.toString().trim();
    }
}
